package com.yzt.message.custom;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yzt.p_base.utils.DisplayUtils;
import com.yzt.message.R;

import java.util.List;

import io.rong.imkit.conversation.messgelist.provider.BaseNotificationMessageItemProvider;
import io.rong.imkit.model.UiMessage;
import io.rong.imkit.widget.adapter.IViewProviderListener;
import io.rong.imkit.widget.adapter.ViewHolder;
import io.rong.imlib.model.MessageContent;
import io.rong.message.InformationNotificationMessage;

/**
 * 撤回消息等通知
 */
public class RXInformationNotificationMessageItemProvider extends BaseNotificationMessageItemProvider<InformationNotificationMessage> {

    public RXInformationNotificationMessageItemProvider() {

    }

    @Override
    protected ViewHolder onCreateMessageContentViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.nomi_item_information_notification_message, parent, false);
        return new ViewHolder(parent.getContext(), rootView);
    }

    @Override
    public boolean isItemViewType(UiMessage item) {
        return item.getMessage().getContent() instanceof InformationNotificationMessage;
    }

    @Override
    protected boolean isMessageViewType(MessageContent messageContent) {
        return messageContent instanceof InformationNotificationMessage;
    }

    @Override
    protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, InformationNotificationMessage content, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
        holder.setText(R.id.rc_msg, content.getMessage());
        View rcContent = parentHolder.getView(R.id.rc_content);
        if (rcContent != null) {
            ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) rcContent.getLayoutParams();
            lp.topMargin = DisplayUtils.dip2px(7);
            lp.bottomMargin = DisplayUtils.dip2px(5);
            rcContent.setLayoutParams(lp);
        }
        View rcTime = parentHolder.getView(R.id.rc_time);
        if (rcTime != null) {
            ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) rcTime.getLayoutParams();
            lp.topMargin = DisplayUtils.dip2px(7);
            rcTime.setLayoutParams(lp);
        }
    }

    @Override
    public Spannable getSummarySpannable(Context context, InformationNotificationMessage data) {
        return data != null && !TextUtils.isEmpty(data.getMessage()) ? new SpannableString(data.getMessage()) : null;
    }
}

